package hot_100;

public class 轮转数组 {
    public static void main(String[] args) {

    }

    public void swap(int[] nums, int l, int r) {
        for (int i = l, j = r; i < j; i++, j--) {
            int temp = nums[i];
            nums[i] = nums[j];
            nums[j] = temp;
        }
    }

    public void rotate(int[] nums, int k) {
        int n = nums.length;
        k = k % n;
        swap(nums, 0, n - k - 1);
        swap(nums, n - k, n - 1);
        swap(nums, 0, n - 1);
    }
}
